package com.haidao.admin.component.entity;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.opencsv.bean.CsvBindByName;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.CustomLog;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.sql.Timestamp;
import java.util.Date;

@Entity
@Data
@Table(name = "user_operation")
public class UserOperation {

    @Id
    @Column(name = "event_id")
    private Long eventId;

    // 账号 需要加密
    @Basic
    @Column(name = "account")
    @NotBlank(message = "账号不能为空")
    private String username;

    @Basic
    @Column(name = "operation_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @NotNull(message = "操作时间不能为空")
    private Date operationTime;

    @Basic
    @Column(name = "ip")
    @NotBlank(message = "IP不能为空")
    private String ip;

    @Basic
    @Column(name = "operation_type")
    @NotBlank(message = "操作类型不能为空")
    private String operationType;

    @Basic
    @Column(name = "source")
    @NotBlank(message = "来源不能为空")
    private String source;

    // 用户行为 需要加密
    @Basic
    @Column(name = "operation_content")
    @NotBlank(message = "操作内容不能为空")
    private String operationContent;

    @Basic
    @Column(name = "hmac")
    private String hmac;

    // 数据是否被篡改
    @Transient
    private boolean changed;

    public String allFields() {
        return username + "," + DateUtil.format(operationTime,"yyyy-MM-dd HH:mm:ss") + "," + ip + "," + operationType + "," + source + "," + operationContent;
    }

}
